package com.wangdao.wechatmall.util;

import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * @ClassName: DateTransformUtil
 * @Description 调整时间格式的工具类
 * @Author Xinhao Yi
 * @Date 2021/7/9  12:12
 */
public class DateTransformUtil {
    /**
     * 把任意时间Date date格式化为 yyyy-MM-dd HH:mm:ss的形式
     * @param date
     * @return
     */
    public static Date dateFormat(Date date){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        //格式化后的时间formattedDate
        Date formattedDate = null;
        try {
            formattedDate=simpleDateFormat.parse(format);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return formattedDate;
    }

    public static String dateStringFormat(Date date){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return simpleDateFormat.format(date);
    }

    /**
     * 转换为当前时间
     * @author shuiYi
     * @param currentTime
     * @return
     */
    public static Date currentTime2Date(long currentTime) {
        Date date = new Date(currentTime);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        Date currentDate = null;
        try {
            currentDate = new Date(simpleDateFormat.parse(format).getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return currentDate;
    }


}
